


import 'package:erp/Collections/Collection.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {

  test("Collection groupSimpleObjects", (){
    var persons = List<Person>();

    persons.add(Person(
        name: "aaa",
        age: 10,
        sex: true
    ));

    persons.add(Person(
        name: "bbb",
        age: 10,
        sex: true
    ));

    persons.add(Person(
        name: "ccc",
        age: 11,
        sex: true
    ));

    persons.add(Person(
        name: "ddd",
        age: 12,
        sex: true
    ));

    persons.add(Person(
        name: "eee",
        age: 11,
        sex: true
    ));

    Map<int, List<Person>> groups = Collection.groupSimpleObjects(persons, (item) => item.age);

    expect(groups.length, 3);
    expect(groups[10].where((item) => item.name == "aaa" || item.name == "bbb").length, 2);
    expect(groups[11].where((item) => item.name == "ccc" || item.name == "eee").length, 2);
    expect(groups[12].where((item) => item.name == "ddd").length, 1);
  });
}

class Person {
  String name;
  int age;
  bool sex;

  Person({this.name, this.age, this.sex});
}
